program expon
implicit none
real :: x
write(*,*) "enter x"
read*,x
write(*,*) "the exponential of",x,"is",expo(x)
write(*,*) "the expected value is",exp(x)

contains
real function expo(y)
real :: y,summ=0
integer :: n=0
do
  summ=summ+(y**n)/fact(n)
  if((y**n)/fact(n)<10e-6) exit
  n=n+1
end do
expo=summ
end function expo

real function fact(n)
integer :: n,x
fact=1
do x=1,n
   fact=fact*x
end do
end function fact
end program expon
